<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>游记推荐</title>
	<#include "../common/header.ftl" >

	<script src="/static/jquery/jquery-form/jquery.form.js" ></script>
	<script src="/static/jquery/jquery-bootstrap/jquery.bootstrap.min.js"></script>
    <script src="/static/My97DatePicker/WdatePicker.js"></script>

	<style>
		.modal-body img{
			width: 100%;
		}
	</style>


	<script>
		$(function () {
			//发布与拒绝
			$('.btn-state').click(function () {
                var id = $(this).data('id');
                var state = $(this).data('state');
                $.get('/travel/changeState.do',{id:id,state:state},function (data) {
                    if(data.success){
                        $.messager.alert('温馨提示','操作成功!  2s后刷新页面');
                        setTimeout(function () {
                            window.location.reload();
                        },2000);
                    }else{
                        $.messager.alert('温馨提示',data.msg);
					}
                })
            });
			
			//推荐的修改
            $('.btn-edit').click(function () {
                var json = $(this).data('json');
                $('#travelCommendModal #travelCommendId').val(json.id);
                $('#travelCommendModal #travelId').val(json.travelId);
                $('#travelCommendModal [name="title"]').val(json.title);
                $('#travelCommendModal [name="subTitle"]').val(json.subTitle);
                $('#travelCommendModal [name="coverUrl"]').val(json.coverUrl);//传递图片的路径
                $('#travelCommendModal #modal-coverUrl').attr('src',json.coverUrl);
                $('#travelCommendModal [name=schedule]').val(json.schedule);
                $('#travelCommendModal [name=type]').val(json.type);
                $('#travelCommendModal #skip').attr('href','/travel/list.do?travelId='+json.travelId);
                $('#travelCommendModal').modal('show');
            });

            //提交修改表单
            $('#saveCommendBtn').click(function () {
                $('#commendForm').ajaxSubmit(function (data) {
                    if(data.success){
                        $.messager.alert('温馨提示','操作成功!  2s后刷新页面');
                        setTimeout(function () {
                            window.location.reload();
                        },2000);
                    }else{
                        $.messager.alert('温馨提示',data.msg);
                    }
                });
            });

            //更换封面按钮触发文件上传框事件
            $('.btn-changePic').click(function () {
                //触发文件上传框
                $('#fileForm [name=file]').click();
            });

            //当文件上传框的值改变就发请求更新
            $('#fileForm').change(function () {
                //判断是否有上传文件
                if($('#fileForm [name=file]').val()){
                    //提交表单
                    $('#fileForm').ajaxSubmit(function (data) {
                        console.log(data);
                        //根据返回结果判断上传结果
                        if(data.status==1){
                                $('#travelCommendModal [name="coverUrl"]').val(data.url);
                                $('#travelCommendModal #modal-coverUrl').attr('src',data.url);
                        }else{
                            $(document).dialog({
                                content:data.msg
                            })
                        }
                    })
                }
            })
			
        })
	</script>
</head>
<body>

<div class="container " style="margin-top: 20px">
	<#include "../common/top.ftl" >
	<div class="row">
		<div class="col-sm-3">
            <!--设置用于菜单回显-->
                <#assign currentMenu="travelCommend">
			<#include "../common/menu.ftl" >
		</div>
		<div class="col-sm-9">
			<div class="row">
				<div class="col-sm-12">
					<h1 class="page-head-line">推荐游记管理</h1>
				</div>
			</div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/travelCommend/list.do" method="post">
                <div class="form-group">
                    <input id="currentPage" type="hidden" name="currentPage" value="${(qo.currentPage)!}">
                    <label for="keyword">关键字:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}" placeholder="请输入标题/副标题">
                </div>

                <select class="c-select form-control" name="type" id="state-query">
                    <option value="0">全部</option>
                    <option value="1">每周推荐</option>
                    <option value="2">每月推荐</option>
                    <option value="3">攻略推荐</option>
                </select>
				<script>
					$('#state-query').val(${(qo.type)!})
				</script>

                <input type="submit" id="btn_query" class="btn btn-success" value="查询">

            </form>

			<table class="table table-striped table-hover" >
				<thead>
				<tr>
                    <th>封面</th>
                    <th>标题</th>
                    <th>副标题</th>
                    <th>推荐时间安排</th>
                    <th>推荐类型</th>
				</tr>
				</thead>
				<#list  pageInfo.list as travelComment>
					<tr>
                        <td>
                            <img src='${(travelComment.coverUrl)!}' width="70px">
                        </td>
                        <td>${(travelComment.title)!}</td>
                        <td>${(travelComment.subTitle)!}</td>
                        <td>${(travelComment.schedule?string("yyyy-MM-dd"))!}</td>
                        <td>${(travelComment.typeName)!}</td>
						<td>
							<button class="btn btn-info btn-xs btn-edit" data-json='${(travelComment.jsonString)!}' >
								修改
							</button>
                        </td>
					</tr>
				</#list>
			</table>

			<#include "../common/page.ftl" >
		</div>
	</div>
</div>

<div id="travelModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">查看内容</h4>
            </div>
            <div class="modal-body content">
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>

<#-- 修改推荐的模态框 -->
<div id="travelCommendModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="commendForm" class="form-horizontal" method="post" action="/travelCommend/saveOrUpdate.do"  style="margin: -3px 118px">
                    <input id="travelCommendId" type="hidden" name="id" value="" />
                    <input id="travelId" type="hidden" name="travel_id" value="" />
                    <div class="form-group">
                        <label class="col-sm-3 control-label">标题</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="title" placeholder="标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">副标题</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="subTitle" placeholder="副标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">封面</label>
                        <div class="col-sm-9">
                            <img width="200px" id="modal-coverUrl" />
                            <input type="hidden" name="coverUrl"  >
                            <input TYPE="button" class="btn btn-info btn-xs btn-changePic" VALUE="更换图片" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">推荐时间</label>
                        <div class="col-sm-9">
                            <input type="text" name="schedule" class="form-control" onclick="WdatePicker()" readonly>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">推荐类型</label>
                        <div class="col-sm-9">
                            <select class="form-control" autocomplete="off" name="type" >
                                <option value="1">每周推荐</option>
                                <option value="2">每月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="text-align: center">
                        <a  target="_blank" id="skip">点击查看游记文章明细</a>
                    </div>
                </form>
                <form id="fileForm" action="/images.do" method="post" enctype="multipart/form-data">
                    <input type="file" class="form-control"  name="file" style="display: none">
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveCommendBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>


</body>
</html>